Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following array:{16, 4, 9, 3, 18... Start Learning for Free
Consider the following array:
{16, 4, 9, 3, 18, 14, 15}
For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, then
  • a)
    A = B
  • b)
    A > B
  • c)
    A < B
  • d)
    A and B are incomparable
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, i...
Understanding Bubble Sort and Selection Sort Comparisons
To determine the relationship between the number of comparisons made by Bubble Sort (A) and Selection Sort (B), we need to analyze how each algorithm operates.
Bubble Sort Comparisons (A)
- In Bubble Sort, adjacent elements are compared and swapped if they are in the wrong order.
- The algorithm makes multiple passes through the array until no swaps are needed.
- For an array of size n, the worst-case scenario involves n-1 comparisons for the first pass, n-2 for the second, and so on, leading to a total of (n-1) + (n-2) + ... + 1 comparisons.
- This results in A = n(n-1)/2 comparisons in the worst case.
Selection Sort Comparisons (B)
- In Selection Sort, the algorithm divides the array into a sorted and an unsorted region.
- It repeatedly selects the minimum element from the unsorted region and moves it to the sorted region.
- The number of comparisons for each pass remains constant at n-1 for the first pass, n-2 for the second, etc., leading to B = n(n-1)/2 comparisons as well.
- However, Selection Sort makes exactly the same number of comparisons regardless of the array's order, which is n(n-1)/2.
Comparison of A and B
- For the given array {16, 4, 9, 3, 18, 14, 15}, both algorithms will have the same number of comparisons in the worst case.
- Thus, A = B.
Conclusion
- The correct answer is option 'C': A < b="" is="" incorrect="" as="" they="" yield="" the="" same="" number="" of="" />
- Therefore, both A and B are equal, leading to a conclusion that they are comparable, but A does not strictly exceed or fall short of B.
Free Test
Community Answer
Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, i...
If there are n elements in the list, then (n - 1) passes are required to compare the elements in the first pass.
Thus, total number of comparisons (A) in bubble sort for a list of N elements = n - 1 = 7 - 1 = 6
In selection sort, selecting the lowest element requires n - 1 + n - 2 + n - 3 + ... comparisons for n elements.
B =  = 21
Hence, A < B
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Question Description
Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer?.
Solutions for Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following array:{16, 4, 9, 3, 18, 14, 15}For the array, if A is the number of comparisons in bubble sort and B is the number of comparisons in selection sort, thena)A = Bb)A > Bc)A < Bd)A and B are incomparableCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev